// 跟平台相关的业务请求
import useRequest from '@/api/request/index.js';

export default {
  // 获取实时监控
  getRealMonitor(param) {
    return new Promise((resolve, reject) => {
      useRequest()
        .post(
          '/public/getRealMonitor',
          {
            channelId: param.data.channelId,
            streamType: param.data.streamType,
          },
          {
            showFailureMsg: false,
          }
        )
        .then(({data}) => {
          resolve(data.data);
        })
        .catch(({data}) => {
          reject(data);
        });
    });
  },
  // 开始语音对讲
  startTalk(param) {
    // TODO 接口参数修改 param格式未知
    return new Promise((resolve, reject) => {
      useRequest()
        .post(
          '/public/startTalk',
          {
            source: param.data.source,
            deviceCode: param.data.deviceCode,
            talkType: param.data.talkType,
            target: param.data.target,
            audioBit: param.data.audioBit,
            audioType: param.data.audioType,
            broadcastChannels: param.data.broadcastChannels,
            sampleRate: param.data.sampleRate,
            talkMode: param.data.talkMode,
            channelSeq: param.data.channelSeq,
          },
          {
            showFailureMsg: false,
          }
        )
        .then(({data}) => {
          resolve(data.data);
        })
        .catch(({data}) => {
          reject(data);
        });
    });
  },
  // 根据时间获取录像回放
  getRecordByTime(param) {
    // TODO 接口参数修改 param格式未知
    return new Promise((resolve, reject) => {
      useRequest()
        .post(
          '/public/getRecordByTime',
          {
            channelId: param.data.channelId,
            streamType: param.data.streamType,
            recordSource: param.data.recordSource,
            recordType: param.data.recordType,
            startTime: param.data.startTime,
            endTime: param.data.endTime,
          },
          {
            showFailureMsg: false,
          }
        )
        .then(({data}) => {
          resolve(data.data);
        })
        .catch(({data}) => {
          reject(data);
        });
    });
  },
  // 根据文件获取录像回放
  getRecordByFile(param) {
    // TODO 接口参数修改 param格式未知
    return new Promise((resolve, reject) => {
      useRequest()
        .post(
          '/public/getRecordByFile',
          {
            channelId: param.data.channelId,
            streamType: param.data.streamType,
            streamId: param.data.streamId,
            recordSource: param.data.recordSource,
            recordType: param.data.recordType,
            startTime: param.data.startTime,
            endTime: param.data.endTime,
            fileName: param.data.fileName,
            ssId: param.data.ssId,
            diskId: param.data.diskId,
          },
          {
            showFailureMsg: false,
          }
        )
        .then(({data}) => {
          resolve(data.data);
        })
        .catch(({data}) => {
          reject(data);
        });
    });
  },
  // 获取普通录像信息列表
  listSimpleRecord(param) {
    // TODO 接口参数修改 param格式未知
    return new Promise((resolve, reject) => {
      useRequest()
        .post(
          '/public/listSimpleRecord',
          {
            channelId: param.data.channelId,
            streamType: param.data.streamType,
            recordSource: param.data.recordSource,
            startTime: param.data.startTime,
            endTime: param.data.endTime,
          },
          {
            showFailureMsg: false,
          }
        )
        .then(({data}) => {
          resolve(data.data);
        })
        .catch(({data}) => {
          reject(data);
        });
    });
  },
  // 云台方向控制
  setPtzDirection(param) {
    // TODO 接口参数修改 param格式未知
    return new Promise((resolve, reject) => {
      useRequest()
        .post(
          '/public/setPtzDirection',
          {
            channelId: param.data.channelId,
            command: param.data.command,
            direct: param.data.direct,
            stepX: param.data.stepX,
            stepY: param.data.stepY,
            extend: param.data.extend,
          },
          {
            showFailureMsg: false,
          }
        )
        .then(({data}) => {
          resolve(data.data);
        })
        .catch(({data}) => {
          reject(data);
        });
    });
  },
  // 云台镜头控制
  setPtzCamera(param) {
    // TODO 接口参数修改 param格式未知
    return new Promise((resolve, reject) => {
      useRequest()
        .post(
          '/public/setPtzCamera',
          {
            channelId: param.data.channelId,
            command: param.data.command,
            operateType: param.data.operateType,
            direct: param.data.direct,
            step: param.data.step,
            extend: param.data.extend,
          },
          {
            showFailureMsg: false,
          }
        )
        .then(({data}) => {
          resolve(data.data);
        })
        .catch(({data}) => {
          reject(data);
        });
    });
  },
  // 云台三维定位
  setPtzPosition(param) {
    // TODO 接口参数修改 param格式未知
    return new Promise((resolve, reject) => {
      useRequest()
        .post(
          '/public/setPtzPosition',
          {
            channelId: param.data.channelId,
            magicId: param.data.magicId,
            pointX: param.data.pointX,
            pointY: param.data.pointY,
            pointZ: param.data.pointZ,
            extend: param.data.extend,
          },
          {
            showFailureMsg: false,
          }
        )
        .then(({data}) => {
          resolve(data.data);
        })
        .catch(({data}) => {
          reject(data);
        });
    });
  },
};
